home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / monitory / lav / uptime.c < prev   
C/C++ Source or Header  |  1993-06-12  |  1KB  |  49 lines

  1. #include <exec/exec.h>
  2. #include <clib/exec_protos.h>
  3.  
  4. #include "lavd.h"
  5.  
  6. static const char    PortName[] = "lavd";
  7. struct MsgPort    *lavdPort = NULL;
  8. struct MsgPort    *RepPort = NULL;    /* Reply port. */
  9. lavdMsg    Req;
  10.  
  11. main()
  12. {
  13.  
  14.     if ((RepPort = CreateMsgPort()) == NULL) {
  15.         PutStr("Couldn't create a message port.\n");
  16.         goto exitmain;
  17.     }
  18.     Req.lm_Message.mn_ReplyPort = RepPort;
  19.     Req.lm_Message.mn_Length = sizeof(lavdMsg);
  20.     Req.Class = LAV_ALL;
  21.  
  22.     /* Forbid so the port doesn't go away... */
  23.     Forbid();
  24.     if ((lavdPort = FindPort(PortName)) == NULL) {
  25.         Permit();
  26.         PutStr("Demon not running.\n");
  27.         goto exitmain;
  28.     }
  29.     PutMsg (lavdPort, &Req);
  30.     Permit();
  31.  
  32.     WaitPort(RepPort);    /* Wait for the reply. */
  33.  
  34.     /* Format the result. */
  35.  
  36.     Printf("Up %ld days, %ld:%02ld, load average %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
  37.         (LONG) Req.Uptime / 86400, (LONG) Req.Uptime / 3600,
  38.         (LONG) ((Req.Uptime / 60) % 60), (LONG) (Req.L1 / 100),
  39.         (LONG) ((Req.L1 - Req.L1 / 100) % 100), (LONG) (Req.L2 / 100),
  40.         (LONG) ((Req.L2 - Req.L2 / 100) % 100), (LONG) Req.L3 / 100,
  41.         (LONG) ((Req.L3 - Req.L3 /100) % 100));
  42.  
  43.       exitmain:
  44.     if (RepPort != NULL) {
  45.         DeleteMsgPort(RepPort);
  46.     }
  47.     exit(0);
  48. }
  49.